package com.drivingtheproject.wifie.wifiexpert;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.drivingtheproject.wifie.data.Profile;

import java.util.ArrayList;

/**
 * Created by i046576 on 16.08.2014.
 */
public class ProfilesAdapter extends ArrayAdapter<Profile> {
    private final Context context;
    private final ArrayList<Profile> values;
    private final LayoutInflater inflater;


    public ProfilesAdapter(Context context, ArrayList<Profile> values) {
        super(context, R.layout.list_item, values);
         inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
        this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item, parent, false);

            holder.labelView = (TextView) convertView.findViewById(R.id.label);
            holder.valueView = (TextView) convertView.findViewById(R.id.value);
            holder.checkBoxActive=(CheckBox) convertView.findViewById(R.id.checkBoxItemActive);

            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        Profile profile =this.values.get(position);
        holder.labelView.setText(profile.getName());
        holder.valueView.setText("Network ID : "+profile.getSSID());
        holder.checkBoxActive.setChecked(profile.isEnable());
        return convertView;
    }

    @Override
    public int getCount() {
        return this.values.toArray().length;
    }

    @Override
    public Profile getItem(int position) {
        return this.values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return this.values.get(position).getId();
    }

    @Override
    public boolean areAllItemsEnabled()
    {
        return true;
    }

    @Override
    public boolean isEnabled(int arg0)
    {
        return true;
    }

    static class ViewHolder {
        TextView labelView;
        TextView valueView;
        CheckBox checkBoxActive;
    }
}
